<?php
!defined('P_W') && exit('Forbidden');

!$_G['allowreport'] && Showmsg('report_right');
InitGP(array(
	'tid',
	'pid'
), 'GP', '2');
InitGP(array(
	'type',
	'own'
));

if (is_int($own)) {
	$ifown = $winduid == $own ? '1' : '0';
} else {
	$ifown = $windid == $own ? '1' : '0';
}
$ifown && Showmsg('report_own');

$checkdata = $db->get_one("SELECT * FROM pw_report WHERE type=" . pwEscape($type) . " AND tid=" . pwEscape($tid) . " AND pid=" . pwEscape($pid));
$checkdata && Showmsg('have_report');

if (empty($_POST['step'])) {
	$ch_type = getLangInfo('other', $type);
	require_once PrintEot('ajax');
	ajax_footer();
} else {
	InitGP(array(
		'reason'
	));
	$pwSQL = pwSqlSingle(array(
		'tid' => $tid,
		'pid' => $pid,
		'uid' => $winduid,
		'type' => $type,
		'reason' => $reason
	));
	$db->update("INSERT INTO pw_report SET $pwSQL");
	Showmsg('report_success');
}
